﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.SessionState;
using WISD.Common;

namespace WISD.CarFriend.Web.Admin.Control
{
    public class Recharge : IHttpHandler, IReadOnlySessionState
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string MemberCardID = NullHelper.NullProcess<string>(context.Request["MemberCardID"], "");
            string RechargeAmount = NullHelper.NullProcess<string>(context.Request["RechargeAmount"], "0");
            string PaidAmount = NullHelper.NullProcess<string>(context.Request["PaidAmount"], "0");
            string Reviser = context.Session["UserCode"].ToString();
            string ReviseDate = NullHelper.NullProcess<string>(context.Request["ReviseDate"], "1888/1/1");
            string Memo = NullHelper.NullProcess<string>(context.Request["Memo"], "");

            string action = NullHelper.NullProcess<string>(context.Request["Action"], "");
            int pageSize = NullHelper.NullProcess<int>(context.Request["PageSize"], 0);
            int pageIndex = NullHelper.NullProcess<int>(context.Request["CurrentPage"], 0);
            string condition = NullHelper.NullProcess<string>(context.Request["Condition"], "");
            string main = NullHelper.NullProcess<string>(context.Request["Main"], "");

            if (action == "Init")
            {
                context.Response.Write(BLL.OA.RechargeModule.GetData(pageSize, pageIndex, condition));
                context.Response.End();
            }

            if (action == "GetOne")
            {
                context.Response.Write(BLL.OA.RechargeModule.GetOne(main));
                context.Response.End();
            }

            if (action == "AddEntity")
            {
                WISD.CarFriend.Model.CFModel.T_CF_OA_Recharge rechargeModel = new Model.CFModel.T_CF_OA_Recharge();
                rechargeModel.MemberCardID = MemberCardID;
                rechargeModel.RechargeAmount = int.Parse(RechargeAmount);
                rechargeModel.PaidAmount = int.Parse(PaidAmount);
                rechargeModel.Reviser = Reviser;
                rechargeModel.ReviseDate = DateTime.Now;
                rechargeModel.Memo = Memo;

                if (BLL.OA.RechargeModule.AddEntity(rechargeModel))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "DeleteEntity")
            {
                //会员卡充值不提供删除功能
                context.Response.Write("");
                context.Response.End();
            }

            if (action == "EditEntity")
            {
                //会员卡充值不提供修改功能
                context.Response.Write("");
                context.Response.End();
            }

            if (action == "GetReviser")
            {
                context.Response.Write("[{\"reviser\":\"" + Reviser + "\"}]");
                context.Response.End();
            }

            if (action == "CheckMemberState")
            {
                BLL.OA.MemberCardModule memberCardBLL = new BLL.OA.MemberCardModule();
                WISD.CarFriend.Model.CFModel.T_CF_OA_MemberCard memberCardModel = memberCardBLL.GetModel(MemberCardID);
                if (memberCardModel != null && memberCardModel.State == 1)
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }
        }


        /// <summary>
        /// IsReusable
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


    }
}